const mysql = require('mysql')



function query(sql, data) {

    const connection = mysql.createConnection({
        host: 'localhost',
        // 数据库端口号
        port: 3306,
        user: 'root',
        password: '123456789',
        database: 'message'
    })
    connection.connect()
    return new Promise((resolve, reject) => {
        connection.query(sql, data, (error, result) => {
            if (error) {
                reject(error)
            } else {
                resolve(result)
            }
        })
        connection.end()
    })
}


module.exports = {
    query
}
